<?php
require("Func-String-To-Binary.php");
$file1 = './Text.txt';
$size = filesize($file1);
echo './Text.txt'."<br/>转化为二进制 ...";

//==============================
//把文件读入一个字符串中
$content = file_get_contents($file1);

//字符串内容转换为二进制
$content = bstr2bin($content);
//==============================

//二进制目标文件
$file2 = './test.txt';

//写入方式打开，将文件指针指向文件头并将文件大小截为零,文件不存在则新建
$fp = fopen($file2, 'w');
fwrite($fp, $content);
fclose($fp);

$size2 = filesize($file2);
echo '<br/>转化成二进制后文件大小为：'.$size2;
//==============================

$content = bin2bstr($content);
$file3 = './new.txt';
$fp = fopen($file3, 'w');
fwrite($fp, $content);
fclose($fp);
?>